package com.chookss.home.document;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.home.entity.DocunmentEntity;
import com.chookss.tools.MyToast;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.SignUtils2;
import com.chookss.tools.Utils;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.callback.ObserverCallback;
import com.chookss.tools.okgoconfig.model.LzyResponse;
import com.chookss.tools.old.SignUtils;
import com.google.gson.reflect.TypeToken;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DocumentDetailActivity extends BaseAct {


    @BindView(R.id.ivDocument)
    ImageView ivDocument;
    @BindView(R.id.common_title_txt)
    TextView common_title_txt;
    @BindView(R.id.tvDocumentName)
    TextView tvDocumentName;
    @BindView(R.id.tvDocumentPeople)
    TextView tvDocumentPeople;
    @BindView(R.id.tvDocumentTime)
    TextView tvDocumentTime;
    @BindView(R.id.tvDocumentDirectory)
    TextView tvDocumentDirectory;
    @BindView(R.id.tvDocumentKeywords)
    TextView tvDocumentKeywords;
    @BindView(R.id.tvDocumentReads)
    TextView tvDocumentReads;
    @BindView(R.id.tvDocumentShares)
    TextView tvDocumentShares;
    private String dataCode;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_document_detail);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState3();
        common_title_txt.setText("详细信息");
        tvDocumentName.setText("dasdsa");
        NavigationTools.saveUseRecord(this,"1","03");
        dataCode=getIntent().getStringExtra("dataCode");
        getData();

    }
    private void getData() {
        Map<String, String> map = new HashMap<>();
        map.put("dataCode", dataCode);
        MyHttpRequest.getDefault().getRequest(new TypeToken<LzyResponse<DocunmentEntity>>() {
        }.getType(), null, Urls.getDetail, SignUtils2.makeSignStr(map), false, new ObserverCallback<DocunmentEntity>() {
            @Override
            public void onSuccess(DocunmentEntity data) {
                if (data != null) {
                    if(tvDocumentName==null){
                        return;
                    }
                    tvDocumentName.setText(data.getDataTitle());
                    tvDocumentPeople.setText(data.getUploadPersonName());
                    tvDocumentTime.setText(Utils.getAccurateDate(data.getUploadTime()));
                    tvDocumentDirectory.setText(data.getDataPath());
                    tvDocumentKeywords.setText(data.getKeyWord());
                    tvDocumentReads.setText(data.getReadNum());
                    tvDocumentShares.setText(data.getShareNum());
                    String fileType = data.getFileType();//文件类型1--word 2 --excel 3--PPT  4pdf
                    String dataType = data.getDataType();//0 --文件夹 1--文件
                    if ("1".equals(dataType)) {
                        if ("1".equals(fileType)) {
                            Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_w).into(ivDocument);
                        } else if ("2".equals(fileType)) {
                            Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_x).into(ivDocument);
                        } else if ("3".equals(fileType)) {
                            Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_p).into(ivDocument);
                        } else if ("4".equals(fileType)) {
                            Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_pdf).into(ivDocument);
                        } else {
                            Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_file_default).into(ivDocument);
                        }
                    } else {
                        Glide.with(DocumentDetailActivity.this).load(R.drawable.icon_folder_big).into(ivDocument);
                    }
                }
            }

            @Override
            public void onError(String errorMsg) {
                MyToast.show(Utils.onErrorTips(errorMsg));
            }
        });
    }
    @OnClick(R.id.common_title_back)
    public void onClick() {
        finish();
    }

}
